refactored but memory error still