Fixed database and retrieval script