tested code & added comments