Switching of ferroelectric thin films