Reduce loops and if statements in method discover_files

Change-Id: I1681467bfa56968336dcb3aa15752f7973585381