more cleanup. removed extra debug statements for readability. refactored various function calls