bug fix #11, improved some coding