cleanup of code to remove debugging, better identation