Fix for accessing invalid memory