I know the code above looks poor.
Perhaps you had better stay there as KS has a few more problems for WS testing: