Fixed some logic, cleaned up some stuffs