changed structure and refactored