rewrite some codes to make them looked neater