Converted code to functions and added bunch of comments