similarity code moved to lib