Replaced string reverse for faster speed.