Split script into separate libraries.

Part of issue #2.
Added missing semicolons.
Removed unused variable.