Refactored some common code into a module; updated readme