using locks instead of synchronized