clean up some code, move some things around