Bug fixes and a bit of formatting