Significantly shortened code

The code has been significantly shortened.