Reworked main code.