converting over to using factories in angularjs