Added tests and minor adjustments.