Add a bunch of filesystem stuff and refactor a bit

This is a massive rebase. MASSIVE.