Conditionally execute a function