Some refactoring.
Does not really work at the moment. File resolution is broken in CmdLet.