File presence check moved to a function