Refactor tile code to be much cleaner