updated getHeading function