added includes for reusable code
moved lots of reusable bits into common