Moved some code from contructor to main.