various minor debugs and refactors