Improve memory management

Removes manual memory management in fastfunc