fixed many bugs also addressing issue #66