more clean-ups and fixes, still need testing