bug fixes and general improvements