Fix bugs related to refactor