fix and improve string parsing