re-factor

re-factor code to make it more re-usable;
remove not needed test code