Cleaned up and added some more comments. Some minor formatting changes.