Refactor some code in IDEA