fixed a few bugs and typos, added verbose debug printing