some bug fixes in position calculations