Update directory.php

Bugfixes and enhancements.