Added logic to save to database