added better error handling and included option to add a file