Removing debug code
Fixing a few edge case bugs