Fixed bug and removed some debug code