adding limit cases to apply function