Fix problem with memory exception