Extract renderBox function