cleaned up code in handleString function