changed and refactored