Rearranged a few things, cleaned up some code