Fixes the invalid pointer problem