Std code adapted from bioreactor -- cleaned crap