refactoring implementation - optimaizations