Fixed bug with incorrect detection, some cleanup