add the j_free function and so on

fix some big bugs and add j_free