Better implementation of #353