Added support for custom instance factories