Implemented `xmalloc` and replaced some `assert`s