separated function to calculate reference frame