Fixed bug in file search routine; code clean-up