finally no leaks and delete/free implemented