Integrating Lee's awesome script + add'l fixes