Added checks for valid database connection before storing instance, also created getInstance function