gps function refined