fixed misc bugs and resolved issue #1