added define-typemap; refactoring