fixed a couple of elusive bugs, arising from poorly written crap