bug fixes and formatting