Added that the first part of the code is not my work.