CHECK THE COMMENTS. SOME FUNCTONS ARE MESSED

BUT IT WORKS!!!