Modified MA simulation as per suggestions by @clbustos