Refactored into lib.
Merge pull request #1 from MrRhodes/temp2

Refactored into lib.