changed code trapping the critical value