bug fixes and code style