Fix mode getting and setting, make things considerably simpler by using stat instead of ls