added reflections and refactored code