Rewritten the script in Ruby to handle coordinates