bug fixes and debugging