Minor fixes, split functionality into an include.