Fix ordering violation warning and crash

This seems to fix it for me. Not sure if this would cause any other issues. Please check.