Source dir improvements

Here is the patch that should improve the source dir handling.