Fixed bugs with database integration