document main module and get rid of some global state