Removed some leaks in the error checking
I have no clue what i changed, but stuff works now