Add some elegant fixes from pull request