Refactored to factories and controllers