using reflection to alleviate type-casting