fix bugs and remove debugging