Improved simulate function.