Small bug fixes and source formatting