more flexible -f function