Add input buffer and fix #14