Fix and clean code

Debug a couple of weird code splotches and remove test code.