Fixed nasty TEMP file bug and conformed to better Ruby standards