This isn't the most elegant bash script.