Code cleanup
Fix position handling, untested