Update Main.java

Revamped rule implementation.