Using function overloading instead of instanceof