cleaned up code and added covariates including flow