cleaned up Expanded logic