A nursery worker who sexually assaulted two young boys and was found with almost 18,000 "vile" images of children has been jailed for eight years.
Alexander Mortimer, 28, filmed and photographed the abuse of the boys and had 17,967 indecent images and 582 videos of children on his computer.
Images found on his laptop and hard drive device ranged from level one "erotic" images to level five, which can include sadism.
Mortimer, who worked at a childcare facility in Lanarkshire, told police he had researched child abuse for his college course when his home was searched by officers.
But in May he admitted a total of five charges relating to the sexual assault of the boys, taking indecent photographs of children and of possessing indecent photos between January 2009 and January this year.
The older of the two boys was interviewed by police and social workers, but the younger boy was deemed too young to give a statement.
At the High Court in Edinburgh on Friday, judge Lady Stacey imposed an extended sentence on Mortimer, meaning he will be supervised for a further seven years on his release from jail.
She told him his actions were a "gross breach of trust".
She said Mortimer, of Rutherglen, South Lanarkshire, was "clearly a danger to children" and placed him on the sex offenders register.
Some of the offences took place in the toilets of an Asda supermarket as well as at an amusement park.
Advocate depute Alison Di Rollo, who is deputy head of the National Sexual Crimes Unit, earlier said Mortimer's conduct had been "premeditated and escalating".
Defence QC Brian McConnachie said Mortimer co-operated with the police investigation by providing passwords to the computer files.
Mr McConnachie also told the court Mortimer had shown he can become "addicted" to things he finds on the internet.
He said Mortimer had a problem with online gambling and at one point actually won £50,000 but later gambled it all away.
He said: "Clearly, in light of of the nature of the offences to which Mr Mortimer has pleaded guilty, there is very little, if anything, that I am going to be able to say which will in any way diminish the serious nature of these offences, and that is not my intention."
In handing down the sentence, Lady Stacey told Mortimer the images on his computer were "vile".
She said: "I will not describe them (the images) any further.
"People who get access to this sort of thing through the internet have to take responsibility for the abuse by whoever took the photographs in the first place.
"You are an intelligent person and you have to take responsibility for what you have done. I have to take note of the planning you did."
Lady Stacey said he would remain under "very robust supervision" for seven years when released from jail.