I know it's late after this pull request was sent, but shouldn't the result of contains be cached and returned, rather than called twice?