remove unused code and check file whether exists