worked out second case (badly)