Tidied up, added comments.
Added simple delay.