big change, rewrite some codes for better maintain