Added code to run on windows and fixed few bugs

Change-Id: I8b19f3443cd8bade4ecceb9fe33bd565b2c5a844
Reviewed-on: http://review.couchbase.org/37880
Reviewed-by: Parag Agarwal <agarwal.parag@gmail.com>
Tested-by: buildbot <build@couchbase.com>