Changed function name to detect() and added IOErrors