Clean up formatting, fixed a couple of bugs