Updated sample code and fixed boundry detection.