Ported Paulo Pires' sample application.