Fixes and Refactoring