fixed bad call to gateway method and do some cleaning of code