refs #289, refs #250: refactored code