This needed to escape code duplication in further development of kernel module. Also this cleanups the code.