Major structure changes

The code was rewritten with switch ... case conditions instead of the
previous if ... else ones.