removed some leaks and the last seg fault