Function simplifications

Simplifications and fixes as suggested by @kballard