code clarified with comments