Moving JS API to a synchronous model.

Fix for #4.