Now with directories

Added directories and some defensive coding