copied in my solution from stypi