Move application logic around; improve exceptions.