refactor validity checking for file upload to increase readability