Lock implementation

Work on locks complete, ready for merging