Modified to work with a file passed as a paramter.