Brought g and f functions out of simulateData
Brought g and f functions to m.r

Could put all of this in a separate file later that we call with source
later to maintain global variable status.