improve file preview related code