Applied some changes as per @rkuhn's pull request.