cleaned up the code, work in progress

Pending tasks:
1. replace Arrays with ArrayBuffers (Float32Array) wherever possible.
2. benchmark performance using jsperf and mention the results in comments.