[refs #389] Refactored the code