Squashed version of #278