Fixed bugs to allow code to run on NodeJS.