Bug fixes
combine rules and main
clean
Fix logical bug