more code cleanup, additional testing