add testing and fix bugs