Cleaned up and added comments

I cleaned up the code a bit, and added some comments. I also retried
using the format that I made, and it was working the way I was
expecting.