Changed the method handling logic to make it more flexible.