Guard claus added to cut and code refactored