Bug Fixes and cleanup