fixed filename issue and added more count checking to alert for potential issues