Fixed a bug in backward pass.
Added more test cases.