Refactored code, working on last functionality