fix bugs in def_method, add tests