Minor modifications and bump to version 0.3.1

Enclosed all javascript within a function scope and some minor code
cleanup.