Add some unit tests and debug some stuff