functions for changing length and ifelse logic