Adapted the code to make it easier for me to read. Found some bugs and corrected them (if( x =3 ) should be if(x == 3))