Incorporating fixes from @robertkowalski