Now outputs correct dates, cleaned up code a little