fixed imports, removed type casting, refactored escape handling