Add script logging and parameterisation
Add state logging
split out lock/unlock