improved example using onInit