added comments on the functions and removed useless variables