Several Bug Fixes and Style Improvements