Split into files by class.

Fixed some bugs, tidied up some of the code. Broke the components file
into multiple files.