Improved style and added comments.