minor code cleanup and refactoring

Change-Id: Ia630fac8909f56a6cbf2c303b5d999d4fc08fabf
Reviewed-on: http://review.couchbase.org/31528
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Pavel Paulau <pavel.paulau@gmail.com>