Added lots of comments and the A algorithm.