refactory code!