re-factoring and tests