Fixed memory leaks, added O3 for fun