Cleaned up code & added lots of comments.