updated code with comments for Robert