change code format to modules, clean up code, add documentation