Replaced calls to define_singleton_method to make it ruby 1.8 compatible