added in bits of missing code