Fixed all leaks and warnings (Thanks Labodj)