Fixing directory reference, error handling