use built-in ruby method to help simplify code
replace metaclass with singleton_class