adding date and refactoring code