bug fixes, improvements, fix #13, fix #14