Fixing bugs memory leaks and buffer and stuff.