fixed inexplicable bug in demo and extended it