Refactor out loc to node into a separate function