DRY changes and service creation.

 - Applied some principles of DRY (Don't Repeat Yourself). [Converted factories into a single factory]
 - Moved localStorage code into a service.