Streamlined code and added more comments.