Fixed bug in binary search and cleaned up some stuff.