Wrote tests and fixed bugs.