FIX: several bug fixes