Added callback, minor cleanup

The main reason for a modification is to add a callback.

In addition I cleaned out all potentially browser incompatible code (console and raw dom methods), and clarified the logic with named functions.

Finally I remove the tester element when it's finished.