Fixed some bugs; tests run successfully.