re-facterize code