Refactor bar generation