Implement tests and fix bugs.