completed bug checking and error checking