Bug fixes and minor formatting changes