format
This gets rid of a lot of duplicated logic that was previously copy&pasted. This commit alos: - Makes it easier to implement new formats - Gets rid of a few bugs - Makes the system more flexible (more options) - Adds a lot of additional tests