a little cleanup, added debug mode with handy messages