added error checking and view stuff