Code restyling

Changed the way kernels are computed.
Additional small improvements and corrections.