output is correct needs error checking