Fixed pointer bugs, still getting segmentation fault. Review needed.