Fixed all memory leaks. TODO: Fix effect bug