stole some more code