Updated code to read from database