refactor some code and tune memory use