There is very good answer here: How to redeem a basic Tx? It works great.
But the algorithm is only for uncompressed addresses/keys, how can I change it to deal with compressed ones?
And the second question - how should I change the procedure to redeem several inputs?