More debugging, variable cleanup, tests