modernized the code a little; added new error package