added example.m and cleaned up some code