added error checking (broken)