added comments and tested code working