Fixed bugs found in local tests