just a little cleanup
expanded error handling + quick fix for header