Refactor so it can be extended and incorporated into other apps.