fixed bug with seg fault