made some changes to moveElem()