added more efficient lock checking
cleaned up some comments