Add asserts and fix some compilation errors