fixed -d and other bugs