Add rest support, more tests and some bug fixed.