Removed definition and added length calculation inside function