no functionality changes; added comments and removed repetitive code