Fixed problem with nullpointerexception for strings with varied lengths