Various bug fixes to prepare the implementation