Source refactoring
Starting to add locks