Patch pushed as c1ed3b048d6644b70221eac2dc9b67420a999462 with some modifications. Thanks.