cleaned up a bit, checking for errors