fixed bugs; cleaned up debug code