Refactored insertInstanceConfig: taking out functions and added test cases