made some functions private; added comments