Performance improvement on when/function.apply

See #105