Cherrypicked first commit for input wrapping