Added memory checking.