added comments and optimized roberts code
fixed merge conflicts