Cleanup code

Cleaning up the code to:
 * Terminate all statements with semicolons
 * Remove unnecessary semicolons
 * Remove unused variables
 * Add hasOwnProperty checks in 'for x in y' loops.

Also made protocol.js::writeObjectData always return an integer.