perhaps place this in a separate file, rather much code