new versions of functions. added memory allocation conditions