First working implementation of #649