Misc fixes to check OOM