Refactored things to use Match<T> method, which reads better and removes a load of type checking and exception throwing code duplication.

Signed-off-by: Martin Evans <martindevans@gmail.com>