A few fixes to move closer to the js version