Completely reworked, split into separate files, spruced up in general.