Made code easier to read and added comments