Moved plotting out of the main function