Implementation of #339