fix bugs and setup test environment