Fix some alerts, code refactoring