Added some comments and improvements, but seems like there's a bug in libata.