optimized leg movement, fixed a memory leak bug