Fix some bugs on handling empty states