Fix bugs and remove most debugging output