Cleaned up JavaScript.
Added documentation.