Better implementation of onFileClicked