lots of tweaks and cleanup