improved error handling. still needs work"