add dumpstatus function and tidy the code