restructure for kindling, improve code