Added tests and debugged.