I copied the code manually since it was uncomfortable to use and too much work to change the naming to an appropriate one :)
Okay, there are many things I would change in order to make this solution as good as possible... It would be endless, so in some places I leave comments, some missed places could be discussed.