fix end of string calculation