Used dirname instead of realpath to avoid extra FS operations