Fixed memory leak, made a few if() easier to read