Remove various ugly bits and improve tests