Wrote kernel and main functions