Added comments, renamed variables, used sprintf() function