Updated and refactored