Fix bugs in master and add migration