left and right confusion plus memory bug fixed