made code more readable; added comments