formatted code, slightly changed min and max year logic