Fixed error and added tests.