Fixes and refactoring.