Move initialization of $error outside switch block

fixes #3