added destructor
added error handling. counter not fully functional