Moved date parsing to function