Working version
Removed segfault line
Minor errors