Added comments and made code easier to read