Refactored sign_transaction