Fixed undefined behavior of returned pointer
Fixed some uninitialized values