Fixed the bug for nonlinearity and added the test.