Tidied up error functionality