Fixes Linux compatibility as well as other bugs

Now handles directories properly, some minor issues and memory issues
are now fixed