Reworking of code for Arduino MEGA.