First attempt at pulling this out of a gen server into a library.