some optimizations for #495