Very small refactoring

Very small refactoring of functions in pw.functions.php and pwapi.function.php to improve clarity and/or performance.