Refactored main kernel module.