added comments and implemented test error check