enhanced the database logic