refactoring and adding length constraints
refactoring and adding length constraints