Fixed memory error solution 2