improved pin handling