FIX: various bug fixes