Fixed memory leaks + Cosmetics