added the possibility for a return value
lockWhile was not using the blocking lock method