fixed regex and added check for local files existence