Lots of changes to make more dynamic