Feature/factory rebase of #404

this is only a rebased version of #404

ojhaujjwal have some problems with git so I rebase the PR for him

Unit tests looks fine with full line and branch coverage.