Fixed several issues found by running -Wall flag