modifying the most awful solution I've ever done