added unit tests and fixed royal match.