clean up the code and add openFileDialog