improvements and refactoring