fix various bugs (thanks Sara)