moved algorithms, calculations, and helpers from models to lib and cleaned up some of the moduels