Refactored src/cycle.js with 'Late Input Functions'

Plus error handling.