added delay and empty filename check