cleaned up 4x code with helper function. NOTE: frame rate went down due to adding many global variables. Need to fix