cleanup and testing logic