Refactor Main.java

- Change logic in processCurrentBuffer().