cleaned up some code on basic example and reorgasnised