Fixed memory error solution 1