handle memory constraints correctly