factor out code in market execution to new function