polish code

use attr_accessor to replace the old function