rewrite index and demo code