code refatored