Added comments and made code more readable