some ugly bug fixes