fixed bugs with new retrieving from db (now partly tested)