Replace some custom code with equivalent code from the framework. This also fixes some fixmes left in the custom code.