add debugging; fix bugs