Made code legible - added functions and comments.