code work, but takes tons of memories