Simplified code and extended tests.