Refactoring for better reading and understanding of instantiate function