Moved the instance creation logic outside of the container: Factory class
Also fixes #40