optimized code for tabs