In wave mechanics when we compute the expectation value of energy we write the following
$$\left<\hat{H}\right>=\int_{-\infty}^\infty\mathrm{d}x\ \psi^*(x)\hat{H}\psi(x)=\int_{-\infty}^\infty\mathrm{d}x\ \psi^*(x)E\psi(x)$$
In Dirac notation it is simply written as
$$\left<\hat{H}\right>=\left<\psi\left|\hat{H}\right|\psi\right>$$
We then chooses some orthogonal basis $\left|x\right>$ and $\left|x'\right>$ in the position space and expand the dirac notation above as follows (with the limits ($-\infty$ to $\infty$) omitted for simplicity)
$$\left<\hat{H}\right>=\left<\psi\left|\hat{H}\right|\psi\right>$$ $$=\int \mathrm{d}x'\int \mathrm{d}x\left<\psi\left|x'\right>\left<x'\right|\hat{H}\left|x\right>\left<x\right|\psi\right>$$ Now since the basis is orthogonal and $\hat{H}$ has eigenvalues $E$ thus the following equation is obeyed
$$\left<x'\left|\hat{H}\right|x\right>=\left<x'\left|E\right|x\right>\tag{1}$$
Since $E$ is just a constant, it can be taken out from the brackets
$$\left<x'\right|E\left|x\right>=E\left<x'\right|\left. x\right>$$ and since the bases are orthogonal $$\left<x'\right |\left. x\right>=\delta(x'-x)\tag{2}$$ Thus the expectation value integral becomes $$=\int\mathrm{d}x\int\mathrm{d}x\left<\psi\left|x'\right>E\delta(x'-x)\left<x\right|\psi\right>$$ Integrating with respect to $x'$ $$=\int\mathrm{d}x\left<\psi\left|x\right>E\left<x\right|\psi\right>=\int\mathrm{d}x\ \psi^*(x)E\psi(x)$$
Are the steps in $(1)$ and $(2)$ legal?
If question 1 is true, is it legal to do a similar treatment for other operators e.g. $\hat{p}$, $\hat{a}^\dagger$, $\hat{j}$ etc. to recover their wave mechanics counterparts of the expectation value from the dirac notation?
If question 1 is false, how to correctly (and preferably mathematically rigorously) recover the wave mechanics result of the expectation value of any operator $\hat{A}$ (not necessary self adjoint/hermitian) from the Dirac notation $\left<\psi\right|\hat{A}\left|\psi\right>$?