Some fixes here and there.

This messy API needs to be sorted out ASAP.