still a few memleaks and a seg fault