Added database connection and logic