code clean-ups and fixes