Clean up
Use more lock's for safety. Some refactories.