Fix for #13 and further enhancements