My first piece of advice would be to use C style strings (zero terminated arrays of chars) instead of Strings. The latter have a reputation for fragmenting memory when manipulated within the program and whilst that is probably not the cause of your problem you would be wise to stop using them.