bug fix and minor edits