fixed mem leaks, add comments and clean