Memory fixes

Only the simple fixes for now, Toroko bug needs more testing.