Tidied up animation frame handling. Re-jigged end event handling.