Fix/reimplement input flushing

See last commit's message for detailed description.