refactor check_document method and add specs