Updated for more flexibility