Added tests and fixed wall determination logic