InvokeClient updated with bugfixes and cleaned up code.