WARNING BUG IN THIS COMMIT
Fixed segmentation fault bug, thank God it took me ages