Refactor tabline code