fix IDEA warnings and refactor code