refs #4610 some code tweaks and optimizations