Codes clean up and moved common functions to a angular service