Fix general code issues

Changes are based on IntelliJ code inspection.