Update test and fix bugs