Moved code into main function