moved repeated code into an invokeObject method

Also added additional comments