fixed a bug, added some test functions