Fixed bug and added unitary tests.