some optimizations for a006255
some optimizations for a006255