test the whole functions and fix the bug