re-applied changes from the melonjs main branch (0.9.7)