Refactored to simplify and to use more angular features