bug fixes and some formatting