update with more-flexible code