Updated to make code more functional Ruby