Fixes warnings, bad code and code style