Reorganize code

Create a general use class; move functions out to separate file.