Fixed a bug with bad data, more test coverage