Fixed some bugs in whereRelated

Signed-off-by: William <william@amovens.com>