This code was written by Dimitrios.