bug fixes; improved the test