Ported: 46e1c3b3e29dbad194d55f4052d9771f4fee9813