Fix bugs from pull #2