Refactored code to implement mvp structure