Some bugs fixed and test example added