Fixed several issues found in static analysis. #24