Refactored the coded and fixes

Added the skipTiles array, renamed some variables to prevent confusion and refactored