various attempts at cpu/memory optimization