Moved code to own header and cpp files.