Fix: split conditions into own method

Before, the if clause fails when is_dir() is true.