Refactored Logic and Logic Test