Updated code to run with more recent Ruby versions