update memory manadgement and fix some problems in API for working with types