fixed C89 incompatibility and incorrect NULL check