moved repeated code into a invokeObject method

Also added additional comments