Extended parsing function and made some bug fix.