Add some comment and improme performance