Fixed a few issues with pull request

I like your improvements, but I found a few issues which these commits address.