FIX: Fix several bugs