Fixes for weird out of memory exception