Bug fixes and clean up