Bug fixes with limit and adding unit tests.