add flags for debug
fix bugs