Add changes from original prototype

From commit

99d09e10a71de7e92a4b0584a253e2e7284ab0e7