Streamlined the code to be more symmetric (and resilient).