Trying to fix seg fault. Made a few minor changes.