Fix bugs, add testing