some code cleanup and sharing tests