got rid of some repeated logic