Fixed a small bug and added some (commented) debug code