Refactored locks a bit