[processing] refactored some helpre functions (contributed by Nathan Woodrow)