put lock inside close routine