First attempt at breaking it out to a usable library.