populate database function works perfectly