Fixing introduced bugs. Now all test cases are working.