Can someone help me compact and clean up this code.

Try here