cleaned up code for example program