Simplified massively. Changed order of event callbacks to try guaranteeing correct metadata.