code cleanup and testing