simplified the logic