simplified material counting
Cleaned code and added isOppCastle function