Rewriting main function. Nfi why it stopped working.