Replace function code where possible

Thanks to Hanno for the tip.