'The school was falling apart around our ears. Staff were depressed, ill and down.

People were leaving and making sideways moves just to get out of here, " says Liz Glancy, the depute rector of Buckhaven High School.

When inspectors visited the school on the Fife coast in 2003 they gave it one of the worst inspection reports ever produced.

The school had major security problems, staff felt intimidated and pupils didn't feel safe. The extensive playing fields skirting the school, once considered a major boon, had been turned into a danger area by local motorbike and quad bike owners. Gangs of teenagers - 17, 18 and 19-year-olds who had left school - regularly trespassed.

The teenage invasion and threatening atmosphere continued inside the school, where up to 30 youngsters could be found loitering in the corridors at any one time, wearing hoodies and caps. None wore uniform. It was, staff now say, impossible to recognise who was and wasn't meant to be there.

In the classrooms, unsurprisingly, things weren't going well. There was a shortage of teachers through both absence and exodus.

Lessons were punctuated by outbursts of bad behaviour. By and large, pupil attainment was falling short of expectations in both Standard Grades and Highers.

Consequently, staff morale was very low.

Even the school building was giving up - the inspectors noted "majorweaknesses in the overall quality of accommodation" and "leaks and water damage affected work in several departments".

Fast forward a couple of years to last night, when David McClure, the rector of Buckhaven High School, spent the evening with Tony and Cherie Blair at 10 Downing Street. He was one of 200 head teachers from across the UK who were chosen to attend a reception hosted by the prime minister in recognition of his hard work and as a reward for "ensuring children and young people get the best start in life".

McClure admits to having been stunned by the invitation, but he also claims to have been in two minds about whether to accept. "It meant being out of the school for a couple of days and if I need to be out of school I always ask if there's a value in my being away, " he says. Colleagues believe that level of dedication is one of the reasons McClure has managed to turn the school around. When Her Majesty's Inspectorate of Education (HMIE) visited Buckhaven High in April and May 2003 one of the few things to win praise was McClure. At that time he was the depute rector and, because his boss was off on sick leave, he was acting head for much of the HMIE visit.

McClure officially took over in December of that year.

In June 2004 HMIE returned to the school. In their interim report they praised the strong lead McClure, a former engineer, had taken. They said: "Leading by example, he had created conditions for improving the school in each of the areas identified in the main points for action."

The inspectors were back again earlier this year and will publish their findings within the next few months. McClure has read the report and describes it as very good, although the details of it are still under wraps.

According to McClure, the support of staff has been a critical factor in what has been achieved at Buckhaven. Micha Weir is the principal teacher of art and design.

There was much joy when staff found out about McClure's appointment, she recalls.

"When they announced it the poppers went off in the assembly hall - people were stamping their feet. I've never seen anything like it, " she says.

The first tasks on McClure's to-do list were discipline and security. The senior management team started to make their presence felt both inside and outside the school. McClure, for whom Buckhaven High is the eighth school in 25 years of teaching, says: "Two or three of us would be in the corridors of the school at any given time - we still are."

A warwas waged on caps and hats by all the staff and the importance of wearing the school uniform for security reasons was highlighted to the pupils and their parents.

The battle wasn't won easily, however.

Buckhaven High serves the area of Levenmouth including the disadvantaged towns of Buckhaven, Kennoway, Methil and Leven. "Social-deprivation indicators such as the infant mortality rate and the death rate make sombre reading, " says Glancy.

The school is in a tough area. In the early days, support from the police was required to move gangs on. One youngster who was particularly loath to leave the school grounds drove his car at McClure.

"There were some difficult and challenging moments and characters, " says McClure, smiling. "[There were] one or two car incidents and threats but there's nothing now. Straight after the inspection we had a fence built so we were able to say:

'These are school grounds, that's the boundary.'We came out and made it clear:

'This belongs to the kids.'" Astaffing crisis was the school's next challenge. Last year the big departments - modern languages, English and maths - were all badly hit, with English and maths already three staff down before the absences increased the pressure.

McClure, a maths teacher, taught his subject a third of the week and taught multiple classes in the assembly hall for another third. Other members of the senior management team did the same. The remainder of McClure's time was spent being rector, monitoring and making sure things were running as smoothly as possible. Paperwork was taken home.

"We're always trying to provide the best education we can, even when the circumstances are difficult, " explains McClure.

Classes were rotated so that where regular teachers were unavailable it wasn't always the same pupils who were being affected. McClure set up after-school homework clubs to allow pupils who had fallen behind to catch up.

"Staff rallied round, taking extra classes, covering for colleagues and sending work home, " he recalls. "Staff who had retired came back and taught classes." The situation became so acute that McClure even brought in his wife Elizabeth, also a maths teacher, to work at Buckhaven High, a move made possible by sending the three youngest of the couple's five children to nursery. McClure stresses that staff shortages were not unique to the Fife school but admits they were worse there, with the reputation of the school making it difficult to attract teachers.

Other changes included the introduction of arrangements to help less academic pupils pursue vocational options at local colleges, if they chose to.

The message that anarchy no longer reigns at Buckhaven High has continued to seep out and the pressure on McClure has now eased. This year the school had more than 60 placing requests - far more than in previous years.

Glancy boasts that the school is fully staffed for the first time in her five years there. But McClure and rest of the management team are still teaching. "Part of the ethos of the school is that we are a team and nobody stands aloof, " says McClure.

There does, however, remain the issue of the building. From a distance it doesn't seem too bad. It looks like any other school built around the 1960s - ugly, in a boxy way. As you get closer, however, the cracks quite literally start to show. Paint is peeling off the entirety of the exterior in great chunks and you wonder how much wall might be coming away with it.

Not only does the building fail to please the eye, it also fails in its main purpose - protecting pupils and teachers from the elements. "In certain classes, when winter comes you freeze and water comes in. In summer you can bake in the same room, " says McClure. A seven-phase refurbishment plan has been drawn up. The first stage, costing GBP2m, is scheduled to begin in October. Provided it gets approval, the entire project should cost about GBP14m and take five years to complete.

What else is left to improve? "Attainment has risen steadily but not dramatically.

That's the main area we'll be concentrating on, " says McClure.

One final measure of McClure's commitment to raising standards is proved by the fact that his own son - who, in terms of catchment, should have attended a school nearer the family home in Cupar - has just started at Buckhaven High. His daughter is also destined to join the school when she finishes primary. "I know this is the best school, " he says. In a few weeks' time we shall know if the inspectors agree.

To sir . . .

with love David Pollock (16) "Mr McClure is well respected. There's always a friendly atmosphere around him. If you're good to him, he's good to you. Everyone realises that."

Nikii Fenton (17) "In first and second year you were scared to walk behind the school because of all the people hanging about there. You wouldn't see anything like that any more."

Colin Slaven (16) "There were a lot of people running about. It wasn't even safe inside sometimes. That has changed and there's nobody running about now."

Jennifer Love (17) "You get the idea that Mr McClure has 100-per cent backing from the staff. They seem happier too and find it easier working with someone who is so well organised"