Reworked main class.

Replaced crazy code with normal code.