code improvements according to @parkr's suggestions