Added comments, made code more readable