Tidying code.
Checking if callbacks are functions before executing them.
Removed I/O from library and added some style to test.
Applying html standards to test.
Removed global vars in javascript.
Documented gateway.js