Refactoring - moved formatDate function and refactored where it is used