Cleaned up code, added example