Refactoring / bug fixing