Refactoring. Fixes