Removed debug lines and fixed minor bugs.