final fixes and tweaks to code