Added logging and asserts to make it easier to understand potential failures