Better written, removed segfaults, etc