implementing recursive lock instead of @synchronized