add lots of exception handling, a little memory improve.