Refactor code to separate core and demo