little improvements and refactoring