Cleaned up logic.