Moved logic from utils to constraints