Improve location error handling, add a lot of comments and documentation.