Various memory improvements