You should get the refund of $3,677, then pay the tax due of $582.
You should have waited to receive your refund before amending, but no harm if you have amended.
**Say "Thanks" by clicking the thumb icon in a post
**Mark the post that answers your question by clicking on "Mark as Best Answer"