refactoring and fixes to Tmx