Final fix for database insertion