Fixed memory leaks and some bugs
Added the license info.