Implemented fine grain locking. Compiles but possibly getting into a infinite loop