Added handeling of undefined values in position function