Fixed undefined behavior of returned pointer
Fixed some uninitialised values