new logic + cleaner code