fix pep8 and stylistic errors from previous commit
fixing extend_lock for race conditions and adding tests