merged some stuff from pull request #1