added console and alert outputs.. code fully tested.