bug fix courtesy of Robert Varga