modified functions and added comments