tweaks to get working; some shared code to lower redundancy