refactory code.