fix error when result is empty
refactor
auto width calculation