Refactored Safe.getFunction to be easier to read