Huge reorganization, also added some other random snippets I had lying around