Fixed a bug and removed some debug code.