Fixed unit tests and misc improvements.