fix bugs and make demo work.