Cleaned up a lot of provided types + invocation code; moved code around to proper modules.