some refactoring, better errors related to escapes