added a general error and fixed some minor bugs