Added error notifications, simplified with bash functions, clean whitespace.