Added tile occupation check. Minor refactoring