clean up code a bit, make more debug statements