added GCC optimization and fixed check on NULL ptr
added GCC Optimization