Rewrite of code to use jquery. Enhanced log