fixed variable m looping issue