NPE fix: reference coordinate calculation