Refactor kernel