refactored code more, just about ready to do materials