Added bonus code and refactored