Fixed a bug and removed debug code