Improve relative path calculation