use dirname instead of string handling