working but uses lots of memory