fixing tests and adding clustering and domain error handling