Better implementation of #263