Refactored code into controller/model, added better resume support