Refactor check length