fix #4, fix #13, address #3 and many other changes