From p1 branch, as this solution looks much easier