Added location calculation code