fixed errors that resulted from duplicated code