fix typo in tests and cleanup code a bit