Changed some assertions & added buffer size check in demo