Code added in watcher to check if the event comes from a folder or a file and some code cleanup