Moved JavaScript code inside a named module for better encapsulation.
Added a maximum number of log entries after which old entries will be discarded.