Adjust to coding style

Moved function out of loop and filtered properties in for-in loop.