Fixed some stuff

- Memory leaks fixed
- Resource leaks fixed
- Wrong number of scanf parameters fixed