worte functions and added comments