address comments and simplify code