Bug fixes
Refactoring