minor bug fixes and code simplification