More tests and some massive bug fixes.