Refactored angular controller