fixed a few bugs introduced in 78f54ada21bb15705998360695b2273a51b73fdf