Cleaning up some structure, moving debugging statements around