Moved core functionality into it's own class