refactored flow.js