Lots of changes in a rush. Seems to work as expected.