fixed tile detection, unforunately it has became quite messy. halp.