Fix #23 and additional improvements.