Code cleanup and added a file_exists check to prevent PHP errors to be thrown (and core edits not to be applied)