Add various small fix and code refractor for the sample demo