modularize location code
fix test