Fixed bug in position change function