Refactor from KCore