modularized code, and refactor for angular best practices