Add separate implementation file

Also resolve all kinds of inclusion problems that arose :-)