Removed debug code and fixed minor bugs.