Update test.js

Added some functions and code improvements.