Fix a bunch of issues, clean up keys and hashtables