Some refactoring, and cached some vars

The material is now being cached so we don’t need to call the slow
GetComponent() every frame.