Refactore core code to its own module