implemented critical sections