most of the functioning unity code