filled in remaining logic. not tested