Troubleshooting and refactoring of ekman averaging